<?php

class Default_ProductController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $product = new Default_Model_Product();
        $this->view->boys = $product->boys()->toArray();
    }

    public function detailAction()
    {
        $product = new Default_Model_Product();
        $this->view->boys = $product->boys()->toArray();
        
        $id = $this->_request->getParam('id');
        $this->view->item = $product->id($id)->toArray();
        
        if(empty($this->view->item))
        {
        	$this->_helper->viewRenderer->setNoRender(true);
        	echo '<h3>Sản phẩm này không tồn tại ! Mong bạn thử lại sau</h3>';
        }
    }

    public function boysAction()
    {
        $product = new Default_Model_Product();
        
        $data = $product->boys()->toArray();
        
        $currentPage = $this->_request->getParam('page',1);
        $paginator = Zend_Paginator::factory($data);
        $paginator->setPageRange(4);
        $paginator->setItemCountPerPage(4);
        $paginator->setCurrentPageNumber($currentPage);
        
        $this->view->boys = $paginator;
    }

    public function girlsAction()
    {
        $product = new Default_Model_Product();
        $this->view->girls = $product->girls(10)->toArray();
    }

    public function searchAction()
    {
        /* Tìm kiếm sản phẩm theo tên */
        $kw = $this->_request->getParam('kw');
        $kw = addslashes($kw);
        
        $product = new Default_Model_Product();
        $result = $product->search($kw);
        
        $currentPage = $this->_request->getParam('page',1);
        $paginator = Zend_Paginator::factory($result);
        $paginator->setPageRange(4);
        $paginator->setItemCountPerPage(4);
        $paginator->setCurrentPageNumber($currentPage);
        
        $this->view->result = $paginator;
    }


}









